package com.atguigu.test01;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;


class MyCallable1 implements Callable<Integer>{
    @Override
    public Integer call() throws Exception {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+" llala1");
        }
        return 1;
    }
}

class MyCallable2 implements Callable<Integer>{
    @Override
    public Integer call() throws Exception {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+" llala2");
        }
        return 2;
    }
}

public class test03 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> task1 = new FutureTask<>(new MyCallable1());
        FutureTask<Integer> task2 = new FutureTask<>(new MyCallable2());
        Thread thread1 = new Thread(task1,"t1");
        Thread thread2 = new Thread(task2,"t2");
        thread1.start();
        thread2.start();
        System.out.println(task1.get());
    }
}
